import 'package:core_package/navigation/tab_title_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_unionad/ui/basice/base_navigation_widget.dart';
import 'package:core_package/core_package.dart';
import 'package:flutter_app_unionad/ui/user_center/widget/financial_details_one_widget.dart';
import 'package:flutter_app_unionad/ui/user_center/widget/financial_details_three_widget.dart';
import 'package:flutter_app_unionad/ui/user_center/widget/financial_details_two_widget.dart';

// ignore: must_be_immutable
class UserCenterItem1Page extends StatefulWidget {
  static const String routeName = "/userCenterItem1Page";
  final int index;

  const UserCenterItem1Page({Key? key, this.index = 0}) : super(key: key);

  @override
  _UserCenterItem1PageState createState() => _UserCenterItem1PageState();
}

class _UserCenterItem1PageState extends State<UserCenterItem1Page> with SingleTickerProviderStateMixin {
  TabController? _controller;
  int index = 0;
  PageController? _pageController;
  List<String> titles = ["提现记录", "兑换记录", "充值记录"];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    if (widget.index != null) {
      index = widget.index;
    }
    _controller = TabController(length: titles.length, vsync: this, initialIndex: index);
    _pageController = PageController(initialPage: index);
  }

  @override
  Widget build(BuildContext context) {
    return BaseNavigationWidget(
      title: "资金明细",
      needScrollView: false,
      child: Column(
        children: [
          buildTitleWidget(),
          MySizeBox(height: 10),
          Expanded(child: buildContent()),
        ],
      ),
    );
  }

  Widget buildContent() {
    return PageView(
      controller: _pageController,
      onPageChanged: (value) {
        _controller?.animateTo(value);
      },
      // physics: NeverScrollableScrollPhysics(),
      children: [
        FinancialDetailOneWidget(),
        FinancialDetailTwoWidget(),
        FinancialDetailThreeWidget(),
      ],
    );
  }

  Widget buildTitleWidget() {
    return Container(
      height: 90.px,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(5.px),
      ),
      child: TabTitleWidget(
        isScrollable: false,
        unSelectLabColor: MyColors.formHex("#272727FF"),
        labelColor: MyColors.formHex("#F8BA35FF"),
        labelStyle: TextStyle(fontSize: MyFont.font13, fontWeight: MyFontWeight.regular),
        unSelectLabStyle: TextStyle(fontSize: MyFont.font13, fontWeight: MyFontWeight.regular),
        tabController: _controller,
        indicatorBottom: 25.px,
        indicatorWidth: 36.px,
        padding: EdgeInsets.symmetric(horizontal: 20.px),
        labelPadding: EdgeInsets.zero,
        indicatorHeight: 1,
        indicatorColor: MyColors.formHex("#F8BA35FF"),
        titleList: titles,
        onTop: (int index) {
          if (mounted) {
            this.index = index;
            setState(() {
              _pageController?.jumpToPage(index);
            });
          }
        },
      ),
    );
  }
}
